﻿using System;



namespace InterfaceAlphabetApplication

{

    // (1) 编写接口InterfaceA

    interface InterfaceA

    {

        void PrintCapitalLetter();

    }



    // (2) 编写接口InterfaceB

    interface InterfaceB

    {

        void PrintLowercaseLetter();

    }



    // 扩展接口：增加打印数字的方法

    interface InterfaceC

    {

        void PrintNumbers();

    }



    // (3) 编写非抽象类Print，实现InterfaceA和InterfaceB

    class Print : InterfaceA, InterfaceB, InterfaceC

    {

        // 实现InterfaceA的printCapitalLetter方法

        public void PrintCapitalLetter()

        {

            Console.WriteLine("大写英文字母表:");

            for (char c = 'A'; c <= 'Z'; c++)

            {

                Console.Write(c + " ");

                if ((c - 'A' + 1) % 10 == 0) // 每10个字母换行

                    Console.WriteLine();

            }

            Console.WriteLine("\n");

        }



        // 实现InterfaceB的printLowercaseLetter方法

        public void PrintLowercaseLetter()

        {

            Console.WriteLine("小写英文字母表:");

            for (char c = 'a'; c <= 'z'; c++)

            {

                Console.Write(c + " ");

                if ((c - 'a' + 1) % 10 == 0) // 每10个字母换行

                    Console.WriteLine();

            }

            Console.WriteLine("\n");

        }



        // 实现InterfaceC的printNumbers方法

        public void PrintNumbers()

        {

            Console.WriteLine("数字表:");

            for (int i = 0; i <= 9; i++)

            {

                Console.Write(i + " ");

            }

            Console.WriteLine("\n");

        }



        // 额外方法：打印所有字符

        public void PrintAll()

        {

            PrintCapitalLetter();

            PrintLowercaseLetter();

            PrintNumbers();

        }

    }



    class Program

    {

        static void Main(string[] args)

        {

            Console.WriteLine("字母表打印程序");

            Console.WriteLine("==============");

            Console.WriteLine();



            // (4) 创建Print的对象并赋值给InterfaceA的变量a

            InterfaceA a = new Print();

            Console.WriteLine("通过InterfaceA变量a调用printCapitalLetter方法:");

            a.PrintCapitalLetter();



            // 创建Print的对象并赋值给InterfaceB的变量b

            InterfaceB b = new Print();

            Console.WriteLine("通过InterfaceB变量b调用printLowercaseLetter方法:");

            b.PrintLowercaseLetter();



            // 使用InterfaceC

            InterfaceC c = new Print();

            Console.WriteLine("通过InterfaceC变量c调用printNumbers方法:");

            c.PrintNumbers();



            // 直接使用Print类

            Console.WriteLine("直接使用Print类:");

            Print print = new Print();

            print.PrintAll();



            // 演示多接口引用

            Console.WriteLine("多接口引用演示:");

            object obj = new Print();



            if (obj is InterfaceA ia)

            {

                ia.PrintCapitalLetter();

            }



            if (obj is InterfaceB ib)

            {

                ib.PrintLowercaseLetter();

            }



            if (obj is InterfaceC ic)

            {

                ic.PrintNumbers();

            }



            Console.ReadLine();

        }

    }

}